/*
 * server_app.h
 */

#ifndef SERVER_APP_H
#define SERVER_APP_H

#include <iostream>
#include <string>
#include "../../common/src/message_queue.h"
#include "../../common/src/thread.h"
#include "../../common/src/session.h"
#include "../../common/src/synchro_list.h"
#include "../../common/src/synchro_vector.h"
#include "session_dispatcher.h"
#include "engine.h"

class ServerApp {
public:
    ServerApp(int& port);
    ~ServerApp();
    void exec();
    void onExit();
    int onCmd();
    void broadcast(const std::string msg);
    bool& getRunning();
    MessageQueue& getMessageQueue();
    SynchroList<Session*>& getSessions();
    SynchroVector<Campaign*>& getCampaigns();
private:
    static const char CMD_EXIT = 'q';
    bool running;
    MessageQueue q;
    SynchroList<Session*> sessions;
    SynchroVector<Campaign*> campaigns;
    SessionDispatcher* dispatcher;
    Engine engine;
    Thread t_dispatch;
    Thread t_engine;
    void loadData();
};

#endif  //SERVER_APP_H

//{+}
